const express = require("express");
const router = express.Router();

// 中间件-进行token认证
const adminAuth = require("../middlewares/admin-auth");
const userAuth = require("../middlewares/user-auth");

//前台路由
let indexRouter = require("../routes/index");
let usersRouter = require("../routes/users");

let postsRouter = require("../routes/posts");
const uploadsRouter = require("../routes/uploads");
const captchaRouter = require("../routes/captcha"); // 验证码
const ordersRouter = require("../routes/orders"); //订单
const alipayRouter = require("../routes/alipay");
const payRouter = require("../routes/pay");

// 后台路由
let adminArticlesRouter = require("../routes/admin/articles");
let adminCategoriesRouter = require("../routes/admin/categories");
let adminUsersRouter = require("../routes/admin/users");
let adminCoursesRouter = require("../routes/admin/courses");
const adminAuthRouter = require("../routes/admin/auth");
const adminChaptersRouter = require("../routes/admin/chapters");
const adminAttachmentsRouter = require("../routes/admin/attachments");
const adminMembershipsRouter = require("../routes/admin/memberships"); //会员
const adminChartsRouter = require("../routes/admin/charts");

// 微信小程序路由
let wechatRouter = require("../routes/wechat");

// 前台路由配置...

router.use("/index", indexRouter);
router.use("/users", userAuth, usersRouter);

router.use("/uploads", adminAuth, uploadsRouter);

router.use("/admin/attachments", adminAuth, adminAttachmentsRouter);

router.use("/posts", postsRouter);
// 管理员登录-不需要认证
router.use("/captcha", captchaRouter);
router.use("/orders", userAuth, ordersRouter);
router.use("/pay", payRouter);
router.use("/alipay", alipayRouter);

// 后台路由配置...
router.use("/admin/articles", adminArticlesRouter);
router.use("/admin/categories", adminAuth, adminCategoriesRouter);
router.use("/admin/users", adminAuth, adminUsersRouter);
router.use("/admin/courses", adminAuth, adminCoursesRouter);
router.use("/admin/chapters", userAuth, adminChaptersRouter);
router.use("/admin/charts", adminAuth, adminChartsRouter);

// 微信小程序路由配置...
router.use("/wechat", wechatRouter);

// 无需登录
router.use("/admin/auth", adminAuthRouter);
router.use("/admin/memberships", adminAuth, adminMembershipsRouter);

module.exports = router;
